import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/v1/user/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/v1/user/info',
    method: 'get',
    params: { token }
  })
}

export function findAll(data) {
  return request({
    url: '/v1/user/findAll',
    method: 'get',
    params: {
      userId: data.userId,
      userName: data.userName,
      role: data.role,
      remove: data.remove
    }
  })
}

export function logout() {
  return request({
    url: '/v1/user/logout',
    method: 'post'
  })
}

export function add(data) {
  console.log(data)
  return request({
    url: '/v1/user/add',
    method: 'post',
    data: {
      userName: data.userName,
      password: data.pass,
      role: data.role
    }
  })
}

export function edit(data) {
  return request({
    url: '/v1/user/edit',
    method: 'put',
    data: {
      userId: data.userId,
      userName: data.userName,
      password: data.pass,
      role: data.role
    }
  })
}

export function reset(data) {
  return request({
    url: '/v1/user/reset',
    method: 'put',
    data: {
      password: data.pass
    }
  })
}

export function findByPage(userName, pageNum, pageSize) {
  return request({
    url: '/v1/user/findByPage',
    method: 'get',
    params: {
      userName: userName,
      pageNum: pageNum,
      pageSize: pageSize
    }
  })
}

export function findByGroup(groupId) {
  return request({
    url: '/v1/user/findByGroup',
    method: 'get',
    params: {
      groupId: groupId
    }
  })
}

export function active(userId) {
  return request({
    url: '/v1/user/active/' + userId,
    method: 'put'
  })
}

export function remove(userId) {
  return request({
    url: '/v1/user/remove/' + userId,
    method: 'delete'
  })
}

